version 14.0
log using "\Users\sgolder\Dropbox\Portfolio Allocation\replication\ariottigolder.log", replace
set more off
#delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      ariotti_golder_data.do                          *;
*       Date:           August 28, 2016                                 *;
*       Author:         Molly Ariotti and Sona Golder                   *;
*       Purpose:      	Create and label some variables.                *;
* 	    Input File:     Africa_govt-party_obs.dta                       *;
*       Output File:    ariottigolder.log                               *;
*       Data Output:    Africa.dta                                      *;             
*       Previous file:  Africa_govt-party_obs.xls --> Stata .dta        *;
*       Machine:        laptop                           				*;
*     ****************************************************************  *;
*     ****************************************************************  *;

*     ****************************************************************  *;
*       Open and summarize dataset. Generate some variables.            *;
*     ****************************************************************  *;

use "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\Africa_govt-party_obs.dta";

sum;

gen portfolioshare = . ;
replace portfolioshare = portfolios / government_portfolios ;

gen seatshare = . ;
replace seatshare = party_seats / government_seats ;

encode partyname, generate(party);
drop partyname;

gen code = (region*100000) + (countrycode*1000) + cabinetcode ;

*     ****************************************************************  *;
*       Label variables                                                 *;
*     ****************************************************************  *;

label var countryname "country name";
label var party_seats "number of legislative seats per party";
label var party "party number or acronym";
label var region "1=Africa, 2=Western Europe, 3=Latin America";
label var cabinetcode "cabinet code";
label var countrycode "country code";
label var code "region, country code, cabinet code";
label var cowcode "cow code";
label var portfolios "number of portfolios per party";
label var formateur "1 = formateur, 0 = otherwise";
label var presidential "1 = presidential, 0 = parliamentary"; 
label var government_portfolios "number of portfolios in the government";
label var government_seats "number of seats controlled by government";
label var seatshare "party share of leg seats controlled by govt";
label var portfolioshare "party share of govt portfolios";
label var year "year in which government begins";


sum;

desc;

*     ****************************************************************  *;
*       Double-check total number of govt portfolios, seats             *;
*     ****************************************************************  *;

egen totalportfolio = total(portfolios), by(cabinetcode);

correlate government_portfolios totalportfolio;

egen totalgovlegseats = total(party_seats), by(cabinetcode);

correlate government_seats totalgovlegseats;

*     ****************************************************************  *;
*       Should be perfectly correlated, so can drop new variables.      *;
*     ****************************************************************  *;

drop totalportfolio totalgovlegseats ;

save "C:\Users\sgolder\Dropbox\Portfolio Allocation\replication\Africa.dta", replace;

*     ****************************************************************  *;
*       How large are Africa cabinets (partisan portfolios)?            *;
*     ****************************************************************  *;

collapse (mean) government_portfolios, by(cabinetcode);

sum government_portfolios;


log close;
exit;
